date_sub
DateTime::sub - Subtract a certain amount of days, months, years, hours, minutes, and seconds to a DateTime object
date_sub()
function subtracts the day, month, year, hour, minute, and second from the specified date.
Subtract 4 days from September 29, 2016:
<?php $date = date_create ( "2016-09-29" ) ; date_sub ( $date , date_interval_create_from_date_string ( "4 days" ) ) ; echo date_format ( $date , "Ymd" ) ; ?>
Try it yourself
date_sub ( object , interval ) ;
parameter | describe |
---|---|
object | Required. Specifies the DateTime object returned by date_create() . |
interval | Required. Specifies the DateInterval object. |